//
// Created by 123 on 2025/1/3.
//

#include "iostream"
using namespace std;

class Anima{
public:
    Anima(){
        cout << "Anima constructor..." << endl;
    }
    virtual void speak()=0;
    //析构函数加上virtual关键字，变成虚析构函数
//    virtual ~Anima(){
//        cout << "Anima virtual destory" << endl;
//    }
    virtual ~Anima()=0;
};

Anima::~Anima(){
    cout << "Anima pure virtual destory" << endl;
}

class Cat : public Anima{
public:
    string* name;
    Cat(string name){
        cout << "Cat constructor..."<< endl;
        this->name = new string (name);
    }
    virtual void speak(){
        cout << *this->name << "cat is speaking" <<endl;
    }
    ~Cat(){
        cout << "cat destory" << endl;
        if(this->name != NULL){
            delete this->name;
            this->name = NULL;
        }
    }
};

int main091(){
    Anima* anima = new Cat("Tom");
    anima->speak();
    delete anima;
    return 0;
}